﻿(function ($) {
    $.fn.NavControl = function (options) {
        options = jQuery.extend({
            viewButton: true,
            editButton: true,
            deleteButton: true,
            itemClick: function (item, event) { }
        }, options);

        $(this).each(function () {
            _setup(this);
        });

        function _setup(item) {
            var controls = '<div class="nav-controls" style="display:none;">';
            if (options.viewButton) {
                controls += '<a act="view" class="nav-button icon-view" href="javascript:void(0)"></a>';
            }

            if (options.editButton) {
                controls += '<a act="edit" class="nav-button icon-edit" href="javascript:void(0)"></a>';
            }

            if (options.deleteButton) {
                controls += '<a act="delete" class="nav-button icon-delete" href="javascript:void(0)"></a>';
            }
            controls += '</div>';

            $(item).css('position', 'relative');
            $(item).append(controls);
            $(item).hover(function () {
                $(item).children('.nav-controls').show();
            }, function () {
                $(item).children('.nav-controls').hide();
            });
            $(item).find('.nav-button').each(function () {
                $(this).click(function () {
                    options.itemClick($(item), $(this).attr('act'));
                });
            });
        }
    }
})(jQuery);